package com.longyang.dao;

import  org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Date;
@Component
@Aspect
public class xmlAdivce {
    @Pointcut("execution(* com.longyang.dao.UserDaoInpl.*(..))")
    private  void pointcut(){

    }
    Date date;
    @Before("pointcut()")
    public  void before(JoinPoint joinpoint){
        date=new Date();
        System.out.println("这是前置通知时间"+date);
        System.out.println("这是前置通知");
        System.out.println("目标代码对象是："+joinpoint.getTarget());
        System.out.println("目标代码需要增强的方法:"+joinpoint.getSignature().getName());
    }
    @AfterReturning("pointcut()")
    public  void afterReturn(JoinPoint joinpoint){
        System.out.println("这是返回通知");
        System.out.println("目标代码对象是："+joinpoint.getTarget());
        System.out.println("目标代码需要增强的方法:"+joinpoint.getSignature().getName());
    }
    @Around("pointcut()")
    public  Object around(ProceedingJoinPoint joinpoint)throws Throwable{
        System.out.println("这是环绕通知前增强");
        Object object=joinpoint.proceed();
        System.out.println("这是环绕通知后增强");
        return object;
    }
    @AfterThrowing("pointcut()")
    public  void afterException(JoinPoint joinpoint){
        System.out.println("这是异常通知");

    }
    @After("pointcut()")
    public  void after(){
        date=new Date();
        System.out.println("这是置通知时间"+date);
        System.out.println("这是后置代码");
    }
}
